#include "TXLib.h"
#include <stdlib.h>

FILE *fileOpen (char *name)
{
    FILE *f = fopen (name, "r");
    if (f == NULL) throw 1;
    return f;
}


int GetIndex (FILE *f)
{
    int a;
    if (feof (f)) throw new std::logic_error ("Unexpected end of file!");
    fscanf (f, "%d ", &a);
    if ((a < 0) || (a > 99)) throw new std::logic_error ("a out of range!");
    return a;
}


void GetFile ()
{
    int x, y;
    FILE *f = fileOpen ("123.txt");
    x = GetIndex (f);
    y = GetIndex (f);

    printf ("123: %d %d\n", x, y);
    fclose (f);
}

void Work ()
{
    int x;

    GetFile ();
    FILE *f2 = fileOpen ("11.txt");
    x = GetIndex (f2);

    printf ("11: %d", x);
    fclose (f2);
}

int main ()
{
    //int size_ = 99999999999999999999;
    //int *array_;
    try
    {
        Work ();
    }
    catch (int ctx)
    {
        printf ("Error with code: %d", ctx);
        return ctx;
    }
    catch (std::logic_error *e)
    {
        printf ("Error with string: %s", e->what ());
        return 100;
    }
    return 0;
    //array_ = (int*)malloc (size_ * sizeof (int));
    //printf ("Ok");
    //return 0;
}
